package com.logic.modular.act.battle;

import com.comment.util.message.ResponseResult;
import com.logic.comment.util.JwtUtils;
import com.logic.config.web.annotation.ActionController;
import com.logic.modular.act.battle.vo.BattleVo;
import com.logic.modular.game.player.match.service.PvpCityServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@Api(tags = "pvp城池信息")
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@ActionController(1)
@RequestMapping("/pvpCityAct")
public class PvpCityAction {
    @Resource
    private PvpCityServiceImpl cityService;

    @ApiOperation("所有查询城池")
    @PostMapping("/list")
    public ResponseResult<?> selectCity(
            @RequestHeader String token
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(cityService.list(
                playerId,
                null,
                null,
                null
        ));
    }

    @ApiOperation("多条件查询城池")
    @PostMapping("/conditionList")
    public ResponseResult<?> conditionList(
            @RequestHeader String token,
            @Valid @RequestBody BattleVo.PvpCityVo.list param
    ) {
        Long playerId = JwtUtils.getPlayerId(token);
        return ResponseResult.success(cityService.list(
                playerId,
                param.getOwnerUid(),
                param.getCoreCityId(),
                param.getType()
        ));
    }


    @ApiOperation("自己城池")
    @PostMapping("/ownerList")
    public ResponseResult<?> listMyCity(
            @RequestHeader String token
    ) {
        return ResponseResult.success(cityService.listMyCity(JwtUtils.getPlayerId(token)));
    }


    @ApiOperation("其他玩家城池")
    @PostMapping("/listEnemyCity")
    public ResponseResult<?> listEnemyCity(
            @RequestHeader String token
    ) {
        return ResponseResult.success(cityService.listEnemyCity(JwtUtils.getPlayerId(token)));
    }

    @ApiOperation("运输兵力")
    @PostMapping("/transport")
    public ResponseResult<?> transport(
            @RequestHeader String token,
            @Valid @RequestBody BattleVo.PvpCityVo.transport param
    ) {
        // 获取数据
        cityService.transport(
                JwtUtils.getPlayerId(token),
                param.getStartCityId(),
                param.getTargetCityId(),
                param.getTroopsQuantity()
        );
        return ResponseResult.success();
    }
}
